#!/bin/bash -ex

SCRIPT_DIR="$(realpath "$(dirname "${0}")")"
ASPT_DIR="$(realpath "$(dirname "${1}")")"
PERF_FILE="$(basename "$(realpath "${1}")")"

FLAMEGRAPH_DIR="/home/aleks/repos/FlameGraph"
FLAMEGRAPH="${FLAMEGRAPH_DIR}/flamegraph.pl"
STACKCOLLAPSE_PERF="${FLAMEGRAPH_DIR}/stackcollapse-perf.pl"

SUMMARY_TOOL="${SCRIPT_DIR}/../build/bin/find_top_sample"

perf script -i "${PERF_FILE}" > "${PERF_FILE}.perf"

${STACKCOLLAPSE_PERF} -all "${PERF_FILE}.perf" > "${PERF_FILE}.fold"
${FLAMEGRAPH}  "${PERF_FILE}.fold" > "${PERF_FILE}.html"
${SUMMARY_TOOL} --perf "${PERF_FILE}.fold"
